Skip to content

fix(compat): add $$typeof to memo() and use it in isMemo() - #5384

Draft
Ultroncn wants to merge 1 commit into
preactjs:mainfrom
Ultroncn:fix/memo-typeof
Draft

Ultroncn wants to merge 1 commit into
preactjs:mainfrom
Ultroncn:fix/memo-typeof

Conversation

@Ultroncn

Copy link
Copy Markdown

Adds 43418typeof = Symbol.for('react.memo') to memo(), matching React and Preact's own forwardRef, so libraries like react-is can recognise Preact memo components. isMemo() now checks 43418typeof instead of the fragile displayName.startsWith('Memo(') heuristic, which misclassified any plain component with displayName = 'Memo(Foo)' as a memo component.

Tests:

  • New 43418typeof test for memo() and a misclassification regression test for isMemo(); both fail on the old code and pass with the fix
  • Un-skipped a forwardRef test case (implementation already existed and passes)
  • compat suite: 379 passed, 4 skipped, 0 failed; oxlint 0 warnings, 0 errors; oxfmt clean; tsc clean

Opening as a draft for community discussion, per CONTRIBUTING.

memo() returned a component without the Symbol.for('react.memo')
marker React sets, so libraries like react-is could not recognise
Preact memo components (forwardRef already sets its own marker).
isMemo() worked around the missing marker with a displayName prefix
check, which also false-positived on any component merely named
Memo(...). Set the marker on memo components and detect it in
isMemo() instead.
@github-actions

Copy link
Copy Markdown

📊 Tachometer Benchmark Results

Summary

A summary of the benchmark results will show here once they finish.

Results

The full results of your benchmarks will show here once they finish.

tachometer-reporter-action v2 for CI

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant